import os

def output_changes_to_file(changes, filename):
    # 确保 results 目录存在
    results_dir = os.path.join(os.path.dirname(__file__), '../results')
    if not os.path.exists(results_dir):
        os.makedirs(results_dir)

    # 生成完整的文件路径
    filepath = os.path.join(results_dir, filename)

    with open(filepath, 'w', encoding='utf-8') as file:
        if changes:
            for change in changes:
                file.write(f'{change[0]} - {change[1]}\n')
        else:
            file.write('No API changes detected.\n')

    print(f'API变更清单已输出到 {filepath}')
